const phoneInput = document.getElementById('phone');
const smsCodeInput = document.getElementById('smsCode');
const sendCodeBtn = document.getElementById('sendCodeBtn');
const nextBtn = document.getElementById('nextBtn');
const agreementCheckbox = document.getElementById('agreement');
let countdown = 0;
let countdownInterval;

function validatePhone(phone) {
    const re = /^1[3-9]\d{9}$/;
    return re.test(phone);
}
function validateSmsCode(code) {
    return /^\d{6}$/.test(code);
}
function updateNextBtnState() {
    const isPhoneValid = validatePhone(phoneInput.value.trim());
    const isSmsValid = validateSmsCode(smsCodeInput.value.trim());
    const isAgreed = agreementCheckbox.checked;
    nextBtn.disabled = !(isPhoneValid && isSmsValid && isAgreed);
}

phoneInput.addEventListener('input', () => {
    updateNextBtnState();
});

smsCodeInput.addEventListener('input', () => {
    updateNextBtnState();
});

agreementCheckbox.addEventListener('change', () => {
    updateNextBtnState();
});

sendCodeBtn.addEventListener('click', () => {
    const phone = phoneInput.value.trim();
    if (!validatePhone(phone)) {
        alert('请输入有效的中国大陆手机号');
        phoneInput.focus();
        return;
    }
    sendCodeBtn.disabled = true;
    sendCodeBtn.textContent = `发送中...`;
    setTimeout(() => {
        alert('验证码已发送至您的手机，请注意查收');
        countdown = 60;
        sendCodeBtn.textContent = `重新发送(${countdown}s)`;
        countdownInterval = setInterval(() => {
            countdown--;
            if (countdown <= 0) {
                clearInterval(countdownInterval);
                sendCodeBtn.disabled = false;
                sendCodeBtn.textContent = '发送验证码';
            } else {
                sendCodeBtn.textContent = `重新发送(${countdown}s)`;
            }
        }, 1000);
    }, 1000);
});

document.getElementById('registerForm').addEventListener('submit', () => {
    updateNextBtnState();
    if (nextBtn.disabled) {
        alert('请填写正确的手机号、验证码并同意协议');
        return false;
    }
    return false;
})
const divs=document.querySelectorAll('.circle')
let countnum=1
const changeCol=()=>{
    countnum+=1
    if(countnum==2){
        divs[1].classList.add('active')
        divs[1].classList.remove('inactive')
    }else if(countnum==3){
        divs[2].classList.add('active')
        divs[2].classList.remove('inactive')
        nextBtn.innerHTML='完成注册'
        
    }else if(countnum==4){
        window.location.href='./index.html'
    }
    
}

